package com.jintian.smart.kernel.security.service;

import com.jintian.smart.base.api.security.entity.OperateLogEntity;
import com.jintian.smart.base.api.security.form.OperateLogQueryForm;
import com.jintian.smart.base.api.security.view.OperateLogVO;
import com.jintian.smart.kernel.common.util.SmartBeanUtil;
import com.jintian.smart.kernel.core.code.UserErrorCode;
import com.jintian.smart.kernel.core.domain.ResponseDTO;
import com.jintian.smart.kernel.security.mapper.OperateLogMapper;
import jakarta.annotation.Resource;
import org.beetl.sql.core.page.PageResult;
import org.springframework.stereotype.Service;

/**
 * 操作日志
 */
@Service
public class OperateLogService {
    @Resource
    private OperateLogMapper operateLogMapper;

    /**
     * @description 分页查询
     */
    public ResponseDTO<PageResult<OperateLogVO>> queryByPage(OperateLogQueryForm queryForm) {
        PageResult<OperateLogVO> pageResult = operateLogMapper.queryByPage(queryForm);
        return ResponseDTO.ok(pageResult);
    }


    /**
     * 查询详情
     *
     * @param operateLogId
     * @return
     */
    public ResponseDTO<OperateLogVO> detail(Long operateLogId) {
        OperateLogEntity operateLogEntity = operateLogMapper.single(operateLogId);
        if (operateLogEntity == null) {
            return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
        }
        OperateLogVO operateLogVO = SmartBeanUtil.copy(operateLogEntity, OperateLogVO.class);
        return ResponseDTO.ok(operateLogVO);
    }
}
